package com.bbm.communitysystem.core.domain;

import com.bbm.communitysystem.tools.DemoDate;
import lombok.Data;

@Data
public class R<T> {

    public static final Integer DEFAULT_CODE = 200;

    public static final Integer DEFAULT_ERROR_CODE = 50000;

    private Integer code;

    private String msg;

    private T data;

    private Long timestamp;

    private String now;

    public R() {
        this.timestamp = System.currentTimeMillis();
        this.now = DemoDate.getNow();
    }


    public static <T> R<T> ok(T data) {
        R<T> r = new R<>();
        r.setCode(R.DEFAULT_CODE);
        r.setData(data);
        return r;
    }

    public static <T> R<T> ok() {
        R<T> r = new R<>();
        r.setCode(DEFAULT_CODE);
        return r;
    }

    public static <T> R<T> ok(String msg,T data) {
        R<T> r = new R<>();
        r.setCode(DEFAULT_CODE);
        r.setMsg(msg);
        r.setData(data);
        return r;
    }

    public static <T> R<T> ok(String msg) {
        R<T> r = new R<>();
        r.setCode(DEFAULT_CODE);
        r.setMsg(msg);
        return r;
    }

    public static <T> R<T> error(String msg) {
        R<T> r = new R<>();
        r.setCode(DEFAULT_ERROR_CODE);
        r.setMsg(msg);
        return r;
    }

    public static <T> R<T> error() {
        R<T> r = new R<>();
        r.setCode(DEFAULT_ERROR_CODE);
        return r;
    }

}
